/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package compiler;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Paul.Kogel
 */
public class Column {

    private String Name;

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public static enum Datatypes {UNKNOWN, VARCHAR, DATE, INTEGER, DOUBLE, TIME, TINYINT, TEXT, TINYTEXT, MEDIUMTEXT, LONGTEXT, CHAR, BINARY, VARBINARY, TINYBLOB, MEDIUMBLOB, BLOB, LONGBLOB, SMALLINT, MEDIUMINT, BIGINT, DECIMAL, FLOAT, REAL, BIT, BOOLEAN, SERIAL, DATETIME, TIMESTAMP, YEAR, GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION};

    public String dtype = "";

    private Datatypes Datatype;

    public Datatypes getDatatype() {
        return Datatype;
    }

    public void setDatatype(Datatypes Datatype) {
        this.Datatype = Datatype;
    }

    public String getDatatypeName(String s) {
        if(s.toUpperCase().equals("BOOLEAN"))
        {
                return "TINYINT";
        }else if(s.toUpperCase().equals("REAL"))
        {
                return "DOUBLE";
        }else{
            return s.toUpperCase();
        }
    }

    public String getDatatypeSign(String s)
    {
        if(s.toUpperCase().equals("VARCHAR") || s.toUpperCase().equals("TEXT") || s.toUpperCase().equals("DATE") || s.toUpperCase().equals("TIME") || s.toUpperCase().equals("CHAR") || s.toUpperCase().equals("TINYTEXT") || s.toUpperCase().equals("MEDIUMTEXT") || s.toUpperCase().equals("LONGTEXT") || s.toUpperCase().equals("BINARY") || s.toUpperCase().equals("VARBINARY") || s.toUpperCase().equals("TINYBLOB") || s.toUpperCase().equals("MEDIUMBLOB") || s.toUpperCase().equals("LONGBLOB") || s.toUpperCase().equals("BLOB") || s.toUpperCase().equals("DATETIME") || s.toUpperCase().equals("TIMESTAMP") || s.toUpperCase().equals("GEOMETRY") || s.toUpperCase().equals("POINT") || s.toUpperCase().equals("LINESTRING") || s.toUpperCase().equals("POLYGON") || s.toUpperCase().equals("MULTILINESTRING") || s.toUpperCase().equals("MULTIPOLYGON") || s.toUpperCase().equals("MULTIPOINT") || s.toUpperCase().equals("GEOMETRYCOLLECTION"))
        {
                return "'";
        }else{
            return "";
        }
    }

    public String getDatatypeExtension(String s)
    {
        if(s.toUpperCase().equals("SERIAL"))
        {
            return "unsigned NOT NULL AUTO_INCREMENT";
        }else if(s.toUpperCase().equals("TIMESTAMP"))
        {
            return "NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP";
        }else{
            return "NOT NULL";
        }
    }

    public String getDatatypeLength(String s)
    {
        if(s.toUpperCase().equals("TINYINT"))
        {
            return "6";
        }else if(s.toUpperCase().equals("MEDIUMINT"))
        {
            return "9";
        }else if(s.toUpperCase().equals("BIGINT"))
        {
            return "20";
        }else if(s.toUpperCase().equals("DECIMAL"))
        {
            return "10";
        }else if(s.toUpperCase().equals("BIT"))
        {
            return "99";
        }else if(s.toUpperCase().equals("TINYINT"))
        {
            return "1";
        }else if(s.toUpperCase().equals("SERIAL"))
        {
            return "20";
        }else if(s.toUpperCase().equals("YEAR"))
        {
            return "4";
        }else if(s.toUpperCase().equals("CHAR"))
        {
            return "99";
        }else if(s.toUpperCase().equals("BINARY"))
        {
            return "99";
        }else if(s.toUpperCase().equals("VARBINARY"))
        {
            return "99";
        }else if(s.toUpperCase().equals("INTEGER"))
        {
            return "99";
        }else if(s.toUpperCase().equals("VARCHAR"))
        {
            return "99";
        }else{
            return "0";
        }
    }

    public boolean datatypeisdefined() {
        boolean b = false;
        if(Datatype != null)
        {
        switch(Datatype)
                        {
                            case INTEGER:
                                b = true;
                                break;
                            case VARCHAR:
                                b = true;
                                break;
                            case TEXT:
                                b = true;
                                break;
                            case DATE:
                                b = true;
                                break;
                            case TIME:
                                b = true;
                                break;
                            case DOUBLE:
                                b = true;
                                break;
                            case TINYINT:
                                b = true;
                                break;
                            case UNKNOWN:
                                b = true;
                                break;
                            default:
                                break;
                        }
        }
        return b;
        }

    private int Length = 0;

    public int getLength() {
        return Length;
    }

    public void setLength(int Length) {
        this.Length = Length;
    }

    public boolean lengthisempty() {
        if(Length != 0){
            return false;
        }else{
            return true;
        }
    }

    private List<String>Values = new ArrayList();

    public List<String> getValues() {
        return Values;
    }

    public void setValues(List<String> Values) {
        this.Values = Values;
    }
    
    private Boolean IsPrimaryKey = false;

    public Boolean getIsPrimaryKey() {
        return IsPrimaryKey;
    }

    public void setIsPrimaryKey(Boolean IsPrimaryKey) {
        this.IsPrimaryKey = IsPrimaryKey;
    }
    
    
    private Boolean IsForeignKey = false;

    public Boolean getIsForeignKey() {
        return IsForeignKey;
    }

    public void setIsForeignKey(Boolean IsForeignKey) {
        this.IsForeignKey = IsForeignKey;
    }

    private Boolean IsAI = false;

    public Boolean getIsAI() {
        return IsAI;
    }

    public void setIsAI(Boolean IsAI) {
        this.IsAI = IsAI;
    }


}
